#include <iostream>
#include <unordered_map>

bool check_map(std::unordered_map<char, int> cnt_map)
{
}

int main()
{
    char c;
    std::cin >> c;

    std::string s;
    std::cin >> s;

    int l = 0;
    int r = 0;
    int max_len = 0;
    std::unordered_map<char, int> cnt_map;
    while (r < s.size())
    {
        if (s[r] == c)
        {
            max_len = std::max(max_len, r - l);
            l = r + 1;
            cnt_map.clear();
        }
        else
        {
            cnt_map[s[r]]++;
            while (cnt_map[s[r]] > 2)
            {
                cnt_map[s[l]]--;
                l++;
            }
            max_len = std::max(max_len, r - l + 1);
        }
        r++;
    }
    std::cout << max_len << std::endl;
    return 0;
}